{	Problem: http://codeforces.ru/problemset/problem/75/B
	Verdict: Accepted
}
var i,n,c,k,g,j,l,r:longint; ch:char; s,m,x,y,q:string; a,b:array[0..110] of longint; t:array[0..110] of string;
procedure qsorta(l,r:longint);
var i,j,x,y:longint;
begin
i:=l;
j:=r;
x:=a[b[(l+r) div 2]];
repeat
  while a[b[i]]>x do inc(i);
  while a[b[j]]<x do dec(j);
  if i<=j then begin
    y:=b[i];
    b[i]:=b[j];
    b[j]:=y;
    inc(i);
    dec(j);
  end;
until i>j;
if l<j then qsorta(l,j);
if i<r then qsorta(i,r);
end;
procedure qsortn(l,r:longint);
var i,j,y:longint; x:string;
begin
i:=l;
j:=r;
x:=t[b[(l+r) div 2]];
repeat
  while t[b[i]]<x do inc(i);
  while t[b[j]]>x do dec(j);
  if i<=j then begin
    y:=b[i];
    b[i]:=b[j];
    b[j]:=y;
    inc(i);
    dec(j);
  end;
until i>j;
if l<j then qsortn(l,j);
if i<r then qsortn(i,r);
end;
begin
c:=1;
fillchar(a,sizeof(a),0);
readln(m);
readln(n);
t[1]:=m;
ch:=#39;
for i:=1 to n do begin
  readln(s);
  x:=copy(s,1,pos(' ',s)-1);
  delete(s,1,pos(' ',s));
  q:=copy(s,1,pos(' ',s)-1);
  if q='posted' then begin
    delete(s,1,pos(' ',s));
    delete(s,1,pos(' ',s));
    y:=copy(s,1,pos(ch,s)-1);
  end else
  if q='commented' then begin
    delete(s,1,pos(' ',s));
    delete(s,1,pos(' ',s));
    y:=copy(s,1,pos(ch,s)-1);
  end else
  if q='likes' then begin
    delete(s,1,pos(' ',s));
    y:=copy(s,1,pos(ch,s)-1);
  end;
  k:=0;
  for j:=1 to c do
    if t[j]=x then begin
      k:=j;
      break;
    end;
  g:=0;
  for j:=1 to c do
    if t[j]=y then begin
      g:=j;
      break;
    end;
  if k=0 then begin
    inc(C);
    k:=c;
    t[k]:=x;
  end; 
  if g=0 then begin
    inc(C);
    g:=c;
    t[g]:=y;
  end;
  if g=1 then begin
    j:=g;
    g:=k;
    k:=j;
  end;
  if k=1 then begin
    if q='commented' then inc(a[g],10);
    if q='posted' then inc(a[g],15);
    if q='likes' then inc(a[g],5);
  end;
end;
for i:=2 to c do b[i]:=i;
qsortA(2,c);
l:=2;
r:=2;
i:=3;
while i<=c do begin
  if a[b[i]]=a[b[i-1]] then inc(r);
  if (a[b[i]]<>a[b[i-1]]) or (i=c) then begin
    if r-l>0 then qsortn(l,r);
    l:=i;
    r:=i;
  end;
  inc(i);
end;
for i:=2 to c do writeln(t[b[i]]);
end.